package com.magina.project.mgdb.config;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassnName :com.magina.project.mgdb.config.EventBusConfig
 * @Author： Magina.Hu
 * @Date： 2019/5/6
 * @Description：
 * @Version: V1.0
 * Copyright (c) 2019-2020 .All rights reserved.
 */
@Configuration
public class EventBusConfig {

    @Bean(name="asyncEventBus")
    public EventBus asyncEventBus() {
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(20);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 20,
                30, TimeUnit.SECONDS, workQueue);
        return new AsyncEventBus(executor);
    }

    @Bean(name="eventBus")
    public EventBus eventBus() {
        return new EventBus();
    }
}